package com.example.education.controller;

import com.example.education.exception.ParamException;
import com.example.education.model.Collect;
import com.example.education.model.Course;
import com.example.education.service.CollectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/interface/collect")
public class CollectController {

    @Autowired
    CollectService collectService;

    @RequestMapping("/insert")
    public boolean insertCollect(Collect collect){
        boolean result = false;
        try {
            result = collectService.insertCollect(collect);
        } catch (ParamException e) {
            e.printStackTrace();
        }
        return result;
    }

    @RequestMapping("/delete")
    public boolean removeCollect(Integer collectId){
        boolean result = false;
        try {
            result = collectService.removeCollect(collectId);
        } catch (ParamException e) {
            e.printStackTrace();
        }
        return result;
    }

    @RequestMapping("/getById")
    public Collect getCollectById(Integer collectId){
        Collect collect = new Collect();
        try {
            collect = collectService.getCollectById(collectId);
        } catch (ParamException e) {
            e.printStackTrace();
        }
        return collect;
    }

    @RequestMapping("/getByUserId")
    public List<Course> getCollectByUserId(Integer userId){
        List<Course> courses = new ArrayList<>();
        try {
            courses = collectService.getCollectByUserId(userId);
        } catch (ParamException e) {
            e.printStackTrace();
        }
        return courses;
    }
}
